3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next

Creating and Deleting Geometric Objects

As you saw briefly in the chapter "Introduction to QuickDraw 3D," QuickDraw 3D supports both immediate and retained modes of defining and rendering a model. Which mode you employ in any particular instance depends on the needs of your application. As suggested earlier, if much of the model remains unchanged from frame to frame, you should use retained mode imaging to create and draw the model. If, however, many parts of the model do change from frame to frame, you should use immediate mode imaging, creating and rendering a model on a shape-by-shape basis.

Listing 5 illustrates how to create a retained box.

Listing 5 Creating a retained box

TQ3GeometryObject               myBox;
TQ3BoxData                      myBoxData;

Q3Point3D_Set(&myBoxData.origin, 1.0, 1.0, 1.0);
Q3Vector3D_Set(&myBoxData.orientation, 0, 2.0, 0);
Q3Vector3D_Set(&myBoxData.minorAxis, 2.0, 0, 0);
Q3Vector3D_Set(&myBoxData.majorAxis, 0, 0, 2.0);
myBox = Q3Box_New(&myBoxData);

Once the code in Listing 5 has been executed, the variable myBox contains a reference to the new box. You can then reuse or dispose of the myBoxData structure, because all subsequent operations on the retained box are performed using myBox . For example, to submit the box for drawing, picking, bounding, or writing, you can execute the following line of code inside a rendering, picking, bounding, or writing loop:

myStatus = Q3Object_Submit(myBox, myView);

To dispose of the retained box, you can call the Q3Object_Dispose function, as follows:

myStatus = Q3Object_Dispose(myBox);

Listing 6 illustrates how to create an immediate box.

Listing 6 Creating an immediate box

TQ3BoxData                      myBoxData;

Q3Point3D_Set(&myBoxData.origin, 1.0, 1.0, 1.0);
Q3Vector3D_Set(&myBoxData.orientation, 0, 2.0, 0);
Q3Vector3D_Set(&myBoxData.minorAxis, 2.0, 0, 0);
Q3Vector3D_Set(&myBoxData.majorAxis, 0, 0, 2.0);

As you can see, you do not have to call any QuickDraw 3D routine to create an immediate box; instead, you simply define the box data in a structure of type TQ3BoxData . To draw an immediate box, you call the Q3Box_Submit function (inside a rendering loop), as follows:

myStatus = Q3Box_Submit(myBox, myView);

Because you didn't create any retained entity, you do not need to dispose of the immediate box.


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next